import { Component, OnInit } from '@angular/core';
import { parts , optionCarType} from '../HuoMoney.model';
import { ApiService } from '../../../../providers/ApiPro.service';


@Component({
  selector: 'app-MoneyCheck',
  templateUrl: './MoneyCheck.component.html',
  styleUrls: ['./MoneyCheck.component.scss']
})
export class MoneyCheckComponent implements OnInit {
  public data = [];
  public _total = 0;
  public pageIndex = 1;
  public parts: parts = new parts();
  public optionCarType = optionCarType;
  public deliverTime:string = null;


  constructor(
    public apiService: ApiService,
  ) { }

  ngOnInit() {
    this.loadAll();
  }

    loadAll(){
    let url = "findfinances";
    //下面的if语句是因为组件的删除会有一个null值残留，影响get请求。
    if(this.deliverTime){
      this.parts.deliverTime=this.apiService.formatDateTime2(this.deliverTime);
    }else if(!this.deliverTime){
      delete this.parts.deliverTime;
    }
    if(!this.parts.carType){
      delete this.parts.carType;    
    }
    console.log(this.parts);
    this.apiService.get(url,this.parts)
      .then(res =>{
        console.log(res);
        this._total = res.totalCount;
        this.data = res.result;
      })
  }

  resetIndex(e) {
        this.parts.setPage(e);
        this.loadAll();
  }

}
